package com.laiyizhan.cms.first.controller;

import com.laiyizhan.cms.first.request.FirstRequest;
import com.laiyizhan.cms.first.service.impl.FirstServiceImpl;
import com.laiyizhan.cms.manager.request.AdminUserRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;


/**
 * Created by SoulWolf on 2017/7/15.
 */
@Controller
@RequestMapping("/admin")
public class FirstController {

    @Autowired
    FirstServiceImpl firstService;

    /*目录页面*/
    @RequestMapping(value = "/first/index/show")
    public String first_index(FirstRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        modelMap.put("state",firstService.First_index(request));
        httpSession.setAttribute("number", 1);
        return "/first/index";
    }

/*一个用于返回页面，一个用于提交页面*/
    @RequestMapping(value = "/first/a/show")
    public String first_a(FirstRequest request) {
        return "/first/main";
    }
    @RequestMapping(value = "/first/a")
    public String First_a_record(ModelMap modelMap,FirstRequest request) {
        String result = firstService.First_a(request);
        modelMap.put("state",firstService.First_index(request));
        if(result=="no"){
            modelMap.put("error","当职称人数不为0的时候，该职称的在职工年人均工资也不能为0");
            modelMap.put("link","/admin/first/a/show");
            return "/error/error";
        }
        return "/first/index";
    }

    @RequestMapping(value = "/first/b/show")
    public String First_b() {
        return "/first/b";
    }
    @RequestMapping(value = "/first/b")
    public String First_b_record(ModelMap modelMap,FirstRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        firstService.First_b(request);
        modelMap.put("state",firstService.First_index(request));
        return "/first/index";
    }

    @RequestMapping(value = "/first/c/show")
    public String First_c() {
        return "/first/c";
    }
    @RequestMapping(value = "/first/c")
    public String First_c_record(ModelMap modelMap,FirstRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        int order = (int)httpSession.getAttribute("number");
        modelMap.put("state",firstService.First_index(request));
        firstService.First_c(request);
        if(order<5){
            httpSession.setAttribute("number",order+1);
        }else{
            return "first/index/show";
        }
        return "/first/c";
    }

    @RequestMapping(value = "/first/d/show")
    public String First_d() {
        return "/first/d";
    }
    @RequestMapping(value = "/first/d")
    public String First_d_record(ModelMap modelMap,FirstRequest request,HttpSession httpSession) {
        firstService.First_d(request);
        request.setoName((String)httpSession.getAttribute("oName"));
        modelMap.put("state",firstService.First_index(request));
        return "/first/index";
    }

    @RequestMapping(value = "/first/e/show")
    public String First_e() {
        return "/first/e";
    }
    @RequestMapping(value = "/first/e")
    public String First_e_record(ModelMap modelMap,FirstRequest request,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        firstService.First_e(request);
        modelMap.put("state",firstService.First_index(request));
        return "/first/index";
    }







}
